package com.my.mall.client.order.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.my.mall.client.order.dao.OrderClientDao;
import com.my.mall.client.order.dto.OrderInfoClientDTO;
import com.my.mall.client.order.dto.OrderInfoItemsClientDTO;
import com.my.mall.client.order.vo.GoodsInfoVo;
import com.my.mall.client.order.vo.OrderClientVo;

@Service
public class OrderClientService {
	@Autowired
	OrderClientDao orderClientDao;

	public int saveOrderInfo(OrderInfoClientDTO orderDTO) {
		orderClientDao.saveOrderInfo(orderDTO);
		int orderId = orderDTO.getId();
		List<OrderInfoItemsClientDTO> itemsList = orderDTO.getOrderItems();
		for (OrderInfoItemsClientDTO oiic:itemsList) {
			oiic.setOrderId(orderId);
		}
		int result = orderClientDao.saveOrderInfoItems(itemsList);
		if (result > 0) {
			return 1;
		} else {
			return 0;
		}

	}
	
	public OrderClientVo getOrderInfo(int id) {
		OrderClientVo orderInfo = orderClientDao.getOrderInfo(id);
		List<GoodsInfoVo> goodsInfoList = orderClientDao.selectGoodsInfoList(id);
		orderInfo.setOrderItems(goodsInfoList);
		return orderInfo;
	}

}